package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserMapper {
  @Select("select * from user")
  List<User> findAll();

  @Select("select * from user where id = #{id}")
  User selectById(Integer id);

  @Update("INSERT INTO `user` VALUES (null, #{name}, #{address}, #{age}, #{sex}, #{phone})")
  @Transactional
  void save(User user);

  @Update("UPDATE USER SET name = #{name}, address = #{address} , age = #{age}, sex = #{sex}, phone = #{phone} where id = #{id} ")
  @Transactional
  void update(User user);

  @Delete("Delete from user where id = #{id}")
  @Transactional
  void delete(Integer id);

  @Select("Select * from user limit ${pageNum},${pageSize}")
  List<User> findPage(Integer pageNum, Integer pageSize);

  @Select("select count(id) from user")
  Integer countuser();
}
